import React, { Component } from 'react'
import {ListBox} from '../../../components'
import { Modal,message } from 'antd';
import { fetchData } from '../../../components/AjaxConsumer'
// 手持用户解锁
export default class ListHandUserLockPage extends Component {
    constructor(props) {
        super(props);

        //行操作列表
        this.rowOperation = [
            
        ];
        //header 操作列表
        this.headerOperation = [
            {
                handleName: 'releaseLock',
                showName: '解锁'
            }
        ];

         //showName、columnName 必有属性， columnWidth 可选，默认100
         this.tableColumn = {
            storageKey: 'ListHandUserLockConfig',
            data:[
                {
                    showName: 'id',
                    columnName: 'userId',
                    columnHidden: true,
                    foreverHidden: true
                },
                {
                    showName: '登录账户名',
                    columnName: 'loginName',
                    columnWidth: 100
                },{
                    showName: '人员姓名',
                    columnName: 'userName'
                }
            ]
        };

        this.searchComponentData = [
            
        ];
    }


    rowHandles = (strHandles, rowObj) => {
        console.log("strHandles===ListResource=======", strHandles);
        if(strHandles === 'releaseLock'){
            this.releaseLock(rowObj);
        }
    }

    // 解锁
    releaseLock = (rowObj) => {
        if(rowObj.length == 0){
            Modal.error({
                title: '错误提示',
                content: '请选择一条数据',
            });
        }else{
            let loginName = rowObj[0].data.loginName;
            const options= {
                url: '/base/auth/release/hand/lock',
                type: 'post',//请求方式
                condition:{loginName:loginName}
            };
            fetchData(this, options, (resData)=>{
                message.success('解锁成功');
                this.refs.listHandUserLock.refreshHandle();
            });
        }        
    }


    render() {
        //当左侧隐藏时，列表宽度加上左侧的宽度，
        //1、当前this.props.isHideLeft 是从页面组件containers/Main/main.js传过来
        //2、this.props.isHideLeft 最顶级赋值是在页面 containers/Main/main.js
        let isHideLeft = this.props.isHideLeft;       
       
        return(
            <div>
                <ListBox
                    ref='listHandUserLock'
                    isHideLeft={isHideLeft}
                    tableColumnData={this.tableColumn}
                    searchComponentData={this.searchComponentData}
                    url='/base/auth/query/hand/lock'
                    title="手持用户解锁"
                    rowHandles={this.rowHandles}
                    rowOperation={this.rowOperation}
                    headerOperation={this.headerOperation}
                    isRowSingle = "true"
                />
               
            </div>
        )
    }
}
